home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE23 / EVENTLST / ELIST.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-05-12  |  1.8 KB  |  80 lines

  1. { *****************************************************
  2.                 TEventList Object
  3.  
  4.   The TEventList is a TList decendant which can store
  5.   TNotifyEvent objects so you can create run-time and
  6.   write-only event 'hooks' in your components.
  7.  
  8.                   Paul Warren
  9.          HomeGrown Software Development
  10.        (c) 1997 Langley British Columbia.
  11.                 (604) 856-6523
  12.          e-mail:  hg_soft@uniserve.com
  13.     Home page: http://users.uniserve.com/~hg_soft
  14.   ***************************************************** }
  15.  
  16. unit Elist;
  17.  
  18. interface
  19.  
  20. uses Classes;
  21.  
  22. type
  23.   { object wrapper for TNotifyEvent }
  24.   TWrapper = class(TObject)
  25.     AEvent: TNotifyEvent;
  26.   end;
  27.  
  28.   TEventList = class(TList)
  29.   private
  30.     { private declarations }
  31.     function GetEvent(Index: Integer): TNotifyEvent;
  32.   public
  33.     { public declarations }
  34.     destructor Destroy; override;
  35.     function AddEvent(Event: TNotifyEvent): integer;
  36.     property Events[Index: Integer]: TNotifyEvent read GetEvent;
  37.   end;
  38.  
  39. implementation
  40.  
  41. { TEventList }
  42. destructor TEventList.Destroy; 
  43. var
  44.   Temp: TObject;
  45. begin
  46.   if Count-1 >= 0 then
  47.   repeat
  48.     { make Temp := first Item }
  49.     Temp := Items[0];
  50.     { free it }
  51.     Temp.Free;
  52.     { delete it }
  53.     Delete(0);
  54.   until Count = 0;
  55.   { call inherited }
  56.   inherited Destroy;  
  57. end;
  58.  
  59. function TEventList.GetEvent(Index: Integer): TNotifyEvent;
  60. var
  61.   P: TWrapper;
  62. begin
  63.   { set var P := desired Item }
  64.   P := Items[Index];
  65.   { return the TNotifyEvent }
  66.   Result := P.AEvent;
  67. end;
  68.  
  69. function TEventList.AddEvent(Event: TNotifyEvent): integer;
  70. var
  71.   P: TWrapper;
  72. begin
  73.   { create a new wrapper }
  74.   P := TWrapper.Create;
  75.   { set its AEvent field := TNotifyEvent }
  76.   P.AEvent := Event;
  77.   { add to list and return its position }
  78.   Result := Add(P);
  79. end;
  80.  
  81. end.
  82.